package client;

import java.util.List;
import java.util.Observable;
import java.util.Random;

import javax.swing.Icon;
import javax.swing.JLabel;

public class IconThread extends Observable implements Runnable {
    JLabel lab;

    Random random = new Random();
    List<Icon> imgs;

    public IconThread(JLabel lab, List<Icon> imgs) {
        this.lab = lab;
        this.imgs = imgs;

    }

    @Override
    public void run() {
        int count = 30;
        while (count > 0) {
            
            int index = random.nextInt(6);
            lab.setIcon(imgs.get(index));
            count--;
            
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        this.setChanged();
        this.notifyObservers();
    }
}